<extend name="Public:base" />
<block name="content">
<div id="primary" class="inner group">
   <!-- START CONTENT -->
      <div id="crumbs" class="theme_breadcumb">
         <a class="home" href="http://yourinspirationweb.com/demo/sommerce">Home Page</a>  &rsaquo;  <a class="no-link current" href="#">My Account</a>
         <div class="breadcrumb-end"></div>
      </div>
      <h2>My Account</h2>
      <table style="width:100%;margin:0px;" cellpadding="0" cellspacing="0" class="short-table blue">
               <thead>
                  <tr>
                     <th style="width:16%">订单编号</th>
                     <th style="width:16%">订单人</th>
                     <th style="width:20%">订单地址</th>
                     <th style="width:16%">收件人电话</th>
                     <th style="width:16%">订单时间</th>
                     <th style="width:16%">商品信息</th>
                  </tr>
               </thead>
            </table>
        <foreach name="orders" item="order_v">
            <table info="mytable" style="width:100%;" cellpadding="0" cellspacing="0" class="short-table white">
               <thead>
                  <tr>
                     <th style="width:16%;height:40px;">{$order_v['bianhao']}</th>
                     <th style="width:16%;height:40px;">{$order_v['name']}</th>
                     <th style="width:20%;height:40px;">{$order_v['zhuzhi']}</th>
                     <th style="width:16%;height:40px;">{$order_v['phone']}</th>
                     <th style="width:16%;height:40px;">{:date('Y-m-d H:i:s',$order_v['time'])}</th>
                     <th style="width:16%;height:40px;">
                        <a info="dianji" href="" class="read-more">查看信息</a>
                     </th>
                  </tr>
               </thead>
               <tbody info="mytbody" style="display:none">
               <tr>
                     <th class="features">商品名称</th>
                     <th class="features">商品单价</th>
                     <th class="features">商品图片</th>
                     <th class="features">商品数量</th>
                     <th class="features">小计</th>
                     <th class="features">操作</th>
                     
                  </tr>
                <foreach name="order_v['cart']" item="cart">
                  <tr>
                     <th class="features"> {$cart['goods']['goods_name']}</th>
                     <td info="price">{$cart['goods']['goods_price']}</td>
                     <td><img height="50px" src="{$cart['goods']['pic']}" alt=""></td>
                     <td>{$cart['num']}</td>
                     <td info="subtotal">-</td>
                     <td>-</td>
                  </tr>
                </foreach>
                    <tr>
                    <td style="text-align:right;">
                    <if condition="$order_v['status'] eq 0">
                        新订单
                    <elseif condition="$order_v['status'] eq 1"/>
                        <a href="" info="queren" oid="{$order_v['id']}" class="read-more" style="float:right">确认收货</a>
                    <elseif condition="$order_v['status'] eq 2"/>
                        已收货                        
                    </if>
                    </td>
                        <td colspan="3" style="text-align:right;">总计:</td>
                        <td><span info="total"></span> 元</td>
                        <td>
                          <a href="" info="shanchu" oid="{$order_v['id']}" class="read-more">删除</a>
                          <a href="" info="shouqi" class="read-more">收起</a>
                        </td>
                    </tr>
               </tbody>
            </table>
        </foreach>
      <!-- #comments -->
   </div>
   <!-- END CONTENT -->
   <!-- START SIDEBAR -->
   <!-- END SIDEBAR -->    
<script type="text/javascript">
    $('td[info="price"]').each(function(){
        var price = parseInt($(this).html());
        var num = parseInt($(this).next().next().html());
        $(this).next().next().next().html(price*num);
    });
    $('table[info="mytable"]').each(function(){
        console.log($(this).find('td[info="subtotal"]'));
        var total = null;
        $(this).find('td[info="subtotal"]').each(function(){
        total+=parseInt($(this).html());
        });
        $(this).find('span[info="total"]').html(total);
    });
    $('a[info="dianji"]').click(function(){
        // $('table[info="mytable"]').slideDown();
        $('tbody[info="mytbody"]').hide(1000);
        $(this).parent().parent().parent().next().show(1000);
        return false;
    });
    $('a[info="shouqi"]').click(function(){
        $(this).parent().parent().parent().hide(1000);
        return false;
    });
    $('a[info="shanchu"]').click(function(){
        var id = $(this).attr('oid');
        var table = $(this).parents('table[info="mytable"]');
        $.ajax({
            url:'/home/goods/order/del',
            type:'post',
            data:{'id':id},
            success:function(mes){
              if(mes=='yes'){
                table.remove();
              }
            }
        });
        return false;
    });
    $('a[info="queren"]').click(function(){
        var id = $(this).attr('oid');
        var a = $(this);
        $.ajax({
            url:'/home/goods/order/status',
            type:'post',
            data:{'id':id},
            success:function(mes){
                if(mes=='yes'){
                    a.parent().html('已收货');
                }else{
                    alert('收货失败, 请刷新后重试');
                }
            }
        });
        return false;
    });
</script>
</block>